/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 * Copyright (c) 2022, Xiaohua Semiconductor Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-28     CDT          first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <rtthread.h>
#include "ledApp.h"

//WDT Config
static int App_WDTCfg(void)
{
    stc_wdt_init_t stcWdtInit;

    /* WDT configuration */
    stcWdtInit.u32CountPeriod   = WDT_CNT_PERIOD65536;
    stcWdtInit.u32ClockDiv      = WDT_CLK_DIV8192;
    stcWdtInit.u32RefreshRange  = WDT_RANGE_0TO100PCT;
    stcWdtInit.u32LPMCount      = WDT_LPM_CNT_STOP;
    stcWdtInit.u32ExceptionType = WDT_EXP_TYPE_RST;
    (void)WDT_Init(&stcWdtInit);

    /* First reload counter to start WDT */
    WDT_FeedDog();
    return 0;
}
INIT_BOARD_EXPORT(App_WDTCfg);


int main(void)
{



    WDT_FeedDog();

    while (1)
    {
        WDT_FeedDog();
//        ledCon(0,500,0,1);
        ledCon(0,500,0,1);
//        ledCon(1,10,500,10);
//        ledCon(2,30,200,10);
//        ledCon(3,60,200,10);
//        ledCon(4,90,200,10);
//        ledCon(5,110,200,10);
        rt_thread_mdelay(1000);
    }
}


#include <finsh.h>
static void reboot(uint8_t argc, char **argv)
{
    rt_hw_cpu_reset();
}
MSH_CMD_EXPORT(reboot, Reboot System);
/**
* Function ota_app_vtor_reconfig
* Description Set Vector Table base location to the start addr of app(RT_APP_PART_ADDR).
*/

#define APP_MOD       1
static int ota_app_vtor_reconfig(void) {
#define NVIC_VTOR_MASK 0x3FFFFF80
#if (APP_MOD==1)
#define RT_APP_PART_ADDR 0x20000
#else
#define RT_APP_PART_ADDR 0x100000
#endif
    /* Set the Vector Table base location by user application firmware definition */
    SCB->VTOR = RT_APP_PART_ADDR & NVIC_VTOR_MASK;
    return 0;
}
//INIT_BOARD_EXPORT(ota_app_vtor_reconfig);


